﻿if (document.domain.split (".").length > 2)
{
	document.domain = document.domain.substring (document.domain.indexOf (".") + 1);
}


var IsIE = (navigator.appName == 'Microsoft Internet Explorer');



IsNull = function (object) {
	return (typeof (object) == 'undefined' || object == null);
}



String.prototype.format = function (args) {
	var str = this;
	return str.replace(String.prototype.format.regex, function(item) {
		var intVal = parseInt(item.substring(1, item.length - 1));
		var replace;
		if (intVal >= 0) {
			replace = args[intVal];
		} else if (intVal === -1) {
			replace = "{";
		} else if (intVal === -2) {
			replace = "}";
		} else {
			replace = ""; 
		}
		return replace;
	});
};

String.prototype.format.regex = new RegExp("{-?[0-9]+}", "g");

String.prototype.replaceAll = function (search, replace) {
	var str = this.toString();

	while (str.indexOf(search) != -1)
	{ str = str.replace(search, replace); }

	return str;
}


String.prototype.replaceNotBasicChars = function () {
	var str = this;
	str = str.replaceAll("\xe1", "a").replaceAll("\xe9", "e").replaceAll("\xed", "i").replaceAll("\xf3", "o").replaceAll("\xfa", "u").
		replaceAll("\xc1", "A").replaceAll("\xc9", "E").replaceAll("\xcd", "I").replaceAll("\xd3", "O").replaceAll("\xda", "U").
		replaceAll("\xf1", "n").replaceAll("\xd1", "N").replace(/[^a-zA-Z\n\t\?\!\@\#\.\,\;\: 0-9]+/g, '');
	return str;
}

String.prototype.regexIndexOf = function (regex, startpos) {
	var indexOf = this.substring(startpos || 0).search(regex);
	return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
}

String.prototype.regexLastIndexOf = function (regex, startpos) {
	regex = (regex.global) ? regex : new RegExp(regex.source, "g" + (regex.ignoreCase ? "i" : "") + (regex.multiLine ? "m" : ""));
	if (typeof (startpos) == "undefined") {
		startpos = this.length;
	} else if (startpos < 0) {
		startpos = 0;
	}
	var stringToWorkWith = this.substring(0, startpos + 1);
	var lastIndexOf = -1;
	var nextStop = 0;
	while ((result = regex.exec(stringToWorkWith)) != null) {
		lastIndexOf = result.index;
		regex.lastIndex = ++nextStop;
	}
	return lastIndexOf;
}


Pad = function (pValue, pPaddingLength, pPaddingValue) {
    
	if (IsNull (pPaddingValue))
	{
		pPaddingValue = "0";
	}

    for (var i = 0; i < pPaddingLength; i++) { pPaddingValue += "0"; }

    return (pPaddingValue + pValue).slice (pPaddingLength * -1);
}



// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function GetCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';

	for (i = 0; i < a_all_cookies.length; i++) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split('=');


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if (cookie_name == check_name) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function SetCookie(name, value, expiresMS, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if (IsNull(expiresMS)) {
		expiresMS = 1 * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date(today.getTime() + (expiresMS));

	document.cookie = name + "=" + escape(value) +
		((expiresMS) ? ";expires=" + expires_date.toGMTString() : "") + 
		";path=" + (path ? path : "/") +
		";domain=" + document.domain +
		((secure) ? ";secure" : "");
}

// this deletes the cookie when called
function DeleteCookie(name, path, domain) {
	if (GetCookie(name)) {
		SetCookie(name, '', 0, path, domain);
	}
}


function GenerateGUID() {
	var result, i, j;
	result = '';
	for (j = 0; j < 32; j++) {
		if (j == 8 || j == 12 || j == 16 || j == 20)
			result = result + '-';
		i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
		result = result + i;
	}
	return result;
}


function GetMainPath ()
{
	return location.protocol + "//" + location.hostname + (location.port.length == 0 ? "" : ":" + location.port) + "/";
}

var esf_MainPath = GetMainPath ();


function GetRelativePath ()
{
	return GetMainPath () + location.pathname.substr (1, location.pathname.lastIndexOf ("/"));
}

var esf_RelativePath = GetRelativePath ();


function FixLinksFrame ()
{
	if (IsIE)
	{
		var elements = document.getElementsByTagName ("link");
		
		for (var i in elements)
		{
			if (typeof (elements [i].href) != "undefined")
			{		
				if (elements [i].href.indexOf (esf_RelativePath) == 0)
				{
					elements [i].href = elements [i].href.substring (esf_RelativePath.length);
				}
			}
		}

		elements = document.getElementsByTagName ("a");

		for (var i in elements)
		{
			if (typeof (elements [i].href) != "undefined")
			{		
				if (elements [i].href.indexOf (esf_RelativePath) == 0)
				{
					elements [i].href = elements [i].href.substring (esf_RelativePath.length);
				}
			}
		}
	}
}


function StopWatch ()
{
	this.startTime = null;
	this.stopTime = null;
	this.running = false;


	this.Start = function()
	{
    	if (this.running == true)
		{
			return;
		}
		else if (this.startTime != null)
		{
			this.stopTime = null;
		}
    
		this.running = true;    
		this.startTime = this.GetTime();
	}

	this.Stop = function()
	{
		if (this.running == false)
		{
			return;    
		}
    
		this.stopTime = this.GetTime();
		this.running = false;
	}

	this.GetDurationms = function()
	{
		if (this.startTime == null || this.stopTime == null)
		{
			return 0;
		}
		else
		{
			return (this.stopTime - this.startTime);
		}
	}

	this.IsRunning = function() { return this.running; }

	this.GetTime = function ()
	{
		var day = new Date();
		return day.getTime();
	}
}


Function.prototype.clone=function(){
    return eval('['+this.toString()+']')[0];
}


function CreateObjectXMLHttpRequest ()
{
	if (window.XMLHttpRequest) 
	{
        return new window.XMLHttpRequest ();
    }
    else 
	{
		try { return new ActiveXObject("Microsoft.XMLHttp") } catch (e) {}
		try { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch (e) {}
        
		throw new Error ("XML Http Request for AJAX is not supported in your browser");
    }
}


function CreateXMLHttpRequest (pURL, pMethodName, pOnComplete, pOnError, pHTTPMethod) 
{
	pOnComplete = pOnComplete.clone ();
		
	if (!IsNull (pOnError))
	{
		pOnError = pOnError.clone ();
	}

	pOnComplete.stopwatch = new StopWatch ();


	return new function () 
	{
		this.Call = function (pParamsObject, pLocalParams)
		{
			var params = "";
			var urlCall = pURL;

			this.URL = pURL;


			this.Handler = CreateObjectXMLHttpRequest (); 
			
			if (typeof (pHTTPMethod) == "undefined")
			{
				pHTTPMethod = "GET";
			}
			
			this.HTTPMethod = pHTTPMethod;

			
			pOnComplete.stopwatch.Start ();


			for (var key in pParamsObject) 
			{
				params += key + "=" + pParamsObject [key] + "&";
			}

			params = params.substring (0, params.length - 1);

			if (this.HTTPMethod == "POST")
			{
				this.Handler.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				this.Handler.setRequestHeader("Connection", "close");
				this.Handler.setRequestHeader("MethodName", pMethodName);
			}
			else
			{
				urlCall = this.URL + "?_methodName=" + pMethodName + "&" + params;
				params = null;
			}		
			

			this.Handler.open (this.HTTPMethod, urlCall, true); 
			
			this.Handler.onreadystatechange = function ()
			{
				if (this.readyState == 4)
				{
					switch (this.status)
					{
						case 200:
							pOnComplete.stopwatch.Stop ();
							
							pOnComplete (this.responseText, pOnComplete.stopwatch.GetDurationms (), pLocalParams); 
						break;

						default:
							if (typeof (this.OnError) == "undefined")
							{
								throw new Error (this.responseText);
							}
							else
							{
								this.OnError (this.responseText, this.status);
							}
						break;
					}
				}
			};

			this.Handler.send (params);		
		}
	};
}


function DownloadXML (pURL)
{
	var xhttp = new CreateObjectXMLHttpRequest ();

	xhttp.open ("GET", pURL, false);
	xhttp.send (null);

	return xhttp.responseXML;
}


function LoadXMLDocument (pStringXML)
{
	var xmlDoc;


	if (IsIE)
	{
		try { xmlDoc = new ActiveXObject ("Microsoft.XMLDOM"); } catch (e) {}
		try { xmlDoc = new ActiveXObject ("Msxml2.DOMDocument"); } catch (e) {}

		if (typeof (xmlDoc) == "undefined")
		{
			throw new Error ("Your browser does not support XML, update it");
		}

		xmlDoc.async= false;
		xmlDoc.loadXML (pStringXML);
	}
	else
	{
		xmlDoc = new DOMParser ().parseFromString (pStringXML, "text/xml");
	}

	return xmlDoc;
}


function Transform_XML_URLXSLT (pxmlDoc, pURLXSLT, pXSLTParams)
{	
	var xsltDoc = DownloadXML (pURLXSLT);
	
	return TransformXSLTHTML (pxmlDoc, xsltDoc, pXSLTParams);
}


function Transform_StringXML_URLXSLT (pStringXML, pURLXSLT, pXSLTParams)
{	
	var xsltDoc = DownloadXML (pURLXSLT);
	
	var xmlDoc = LoadXMLDocument (pStringXML);

	return TransformXSLTHTML (xmlDoc, xsltDoc, pXSLTParams);
}


function TransformXSLTHTML (pxmlDoc, pxsltDoc, pXSLTParams) 
{
    try
	{
		if (typeof (XSLTProcessor) != "undefined") 
		{
			var xsltProcessor = new XSLTProcessor();
			xsltProcessor.importStylesheet(pxsltDoc);
        
			if (typeof (pXSLTParams) != "undefined")
			{
				for (var key in pXSLTParams) 
				{
					xsltProcessor.setParameter (null, key, pXSLTParams [key]);
				}
			}

			var xmlFragment = xsltProcessor.transformToFragment(pxmlDoc, document);
		
			if (typeof (xmlFragment.childNodes [0].outerHTML) != "undefined")
			{
				return xmlFragment.childNodes [0].outerHTML;
			}

			return xmlFragment.childNodes [1].outerHTML;
		}
    
		else 
		{
			var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
			var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
			var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");

			xmlDoc.loadXML (pxmlDoc.xml);
			xslDoc.loadXML (pxsltDoc.xml);
			 
			xslt.stylesheet = xslDoc;

			var xslProc = xslt.createProcessor();
			xslProc.input = xmlDoc;
			 
			for (var keyp in pXSLTParams) 
			{
				xslProc.addParameter (keyp, pXSLTParams [keyp]);
			}

			xslProc.transform();

			return xslProc.output;
		}
	
    }
    catch (e) 
	{            
		throw new Error ("XSLT processing error: " + e.Message);
    }
}


GetViewPort = function ()
{
	var elem = (document.compatMode === "CSS1Compat") ? document.documentElement : document.body;

	return { Height: elem.clientHeight, Width: elem.clientWidth };
}


GetDocumentSize = function ()
{
	var pElem = (document.compatMode === "CSS1Compat") ? document.documentElement : document.body;
	
	var result = {};


	result.Height = Math.max (pElem.scrollHeight, pElem.offsetHeight, pElem.clientHeight);
	
	result.Width = Math.max (pElem.scrollWidth, pElem.offsetWidth, pElem.clientWidth);
    
	return result;
}


GetDocumentScroll = function ()
{
	var result = {};


	if (typeof( window.pageYOffset ) == 'number') 
	{
		//Netscape compliant
		result.Y = window.pageYOffset;
		result.X = window.pageXOffset;
	} 
	else if (document.body && ( document.body.scrollLeft || document.body.scrollTop)) 
	{
		//DOM compliant
		result.Y = document.body.scrollTop;
		result.X = document.body.scrollLeft;
	} 
	else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
	{
		//IE6 standards compliant mode
		result.Y = document.documentElement.scrollTop;
		result.X = document.documentElement.scrollLeft;
	}
  
	return result;
}


GetElementSize = function (pElem)
{
	var result = {};


	result.Height = Math.max (pElem.scrollHeight, pElem.offsetHeight, pElem.clientHeight);
	result.Width = Math.max (pElem.scrollWidth, pElem.offsetWidth, pElem.clientWidth);

	return result;
}


CenterWindow = function (pElem)
{
	var docSize = GetDocumentSize ();
	var docViewPort = GetViewPort ();
	var elemSize = GetElementSize (pElem);
	
	pElem.style.position = 'fixed';

	pElem.style.top = ((docViewPort.Height - elemSize.Height) / 2) + 'px';
	
	pElem.style.left = ((docSize.Width - elemSize.Width) / 2) + 'px';
}


function IsNotSameParent() 
{
	return (parent.location != location);
}


FixContentSizes = function () 
{
	var ifrContents = document.getElementById ("ifrContents");
	
	var callJS = 'var ifrContents = document.getElementById ("ifrContents"); ifrContents.style.height = ifrContents.contentWindow.GetDocumentSize ().Height + "px";';

	if (!IsNull (ifrContents))
	{
		ifrContents.style.height = '0px';
				
		var inter = window.setInterval (
			function () 
			{
				if(ifrContents.contentWindow.document.readyState = "complete") 
				{
					window.clearInterval (inter);
			  
					ifrContents.style.height = ifrContents.contentWindow.GetDocumentSize ().Height + 'px';
				}
			}, 100);

		window.setTimeout (callJS, 500);
		window.setTimeout (callJS, 1000);
		window.setTimeout (callJS, 2000);
		window.setTimeout (callJS, 2000);
		window.setTimeout (callJS, 5000);
		window.setTimeout (callJS, 10000);
	}
	else if (IsNotSameParent () && typeof (parent.FixContentSizes) != "undefined")
	{
		parent.FixContentSizes ();
	}
}


IsVisible = function (pElem) {

	var result = true;

	
	if (IsNull(pElem)) { return false; }

	if (typeof (pElem.style.visibility) != 'undefined') { result = result && (pElem.style.visibility != 'hidden'); }

	if (typeof (pElem.style.display) != 'undefined') { result = result && (pElem.style.display != 'none'); }

	return result;
}


ShowHide = function (pElem, pShowHide)
{
	if (!IsNull (pShowHide))
	{
		if (pShowHide)
		{
			Show (pElem);
		}
		else
		{
			Hide (pElem);
		}
	}
	else
	{
		ShowHide (pElem, !IsVisible (pElem));
	}
}


Hide = function (pElem) {
	if (!IsNull(pElem)) {
		pElem.style.display = 'none';
		pElem.style.visibility = 'hidden';
	}
}


Show = function (pElem, pzIndex) {
	if (!IsNull(pElem)) {
		pElem.style.visibility = 'visible';

		if (pElem.tagName == 'DIV') {
			pElem.style.display = 'block';
		}
		else {
			pElem.style.display = '';
		}
	}
}



var esfdivFullCoverWithOpacity;


function CreateFullCoverWithOpacity ()
{
	esfdivFullCoverWithOpacity = document.getElementById ('esfdivFullCoverWithOpacity');


	if (IsNull (esfdivFullCover))
	{
		esfdivFullCoverWithOpacity = document.createElement ("div");
		esfdivFullCoverWithOpacity.id = "esfdivFullCoverWithOpacity";
	}

	document.body.appendChild (esfdivFullCoverWithOpacity);

	return esfdivFullCoverWithOpacity;
}


var esfdivFullCover;


function CreateFullCover ()
{
	esfdivFullCover = document.getElementById ('esfdivFullCover');


	if (IsNull (esfdivFullCover))
	{
		esfdivFullCover = document.createElement ("div");
		esfdivFullCover.id = "esfdivFullCover";
	}

	document.body.appendChild (esfdivFullCover);

	return esfdivFullCover;
}


var esfImageGallery;


function CreateImageGallery ()
{
	esfdivImageGallery = document.getElementById ('esfdivImageGallery');
	

	if (IsNull (esfdivImageGallery))
	{
		esfdivImageGallery = document.createElement ("div");
		esfdivImageGallery.id = "esfdivImageGallery";
	}
	
	document.body.appendChild (esfdivImageGallery);


	esfImageGallery = 
	{
		Init : function ()
		{
			var heightGen;


			this.divImageGallery = document.getElementById ('esfdivImageGallery');


			heightGen = Math.max (GetViewPort ().Height, 600);

			this.divImageGallery.innerHTML = '<div class="divPager" id="esfdivImageGallery_divPager"><div>Pagina</div><div id="esfdivImageGallery_lblPageIndex"></div><div>de</div><div id="esfdivImageGallery_lblPageCount"></div> <div id="esfdivImageGallery_lnkPrevious" onclick="esfImageGallery.ShowPrevious ();" class="esfdivImageGallery_lnkPrevious">Anterior</div> <div id="esfdivImageGallery_lnkNext" onclick="esfImageGallery.ShowNext ();" class="esfdivImageGallery_lnkNext">Siguiente</div> <div onclick="esfImageGallery.Hide ();" id="esfdivImageGallery_lnkClose">Cerrar</div></div>' + 
				'<div id="esfdivImageGallery_divImageSquare"><div id="esfdivImageGallery_divImageList"></div><div id="esfdivImageGallery_divImageContainer"><div id="esfdivImageGallery_lblLoadingMessage"></div><img id="esfdivImageGallery_imgImage" onload="esfImageGallery.OnImageLoad ();"></img><div id="esfdivImageGallery_divHits"></div></div></div>';
			this.divImageGallery.style.height = (heightGen - 20) + 'px'; 
			
			this.lblPageIndex = document.getElementById ('esfdivImageGallery_lblPageIndex');
			this.lblPageCount = document.getElementById ('esfdivImageGallery_lblPageCount');
			this.lnkPrevious = document.getElementById ('esfdivImageGallery_lnkPrevious');
			this.lnkNext = document.getElementById ('esfdivImageGallery_lnkNext');
			this.lblLoadingMessage = document.getElementById ('esfdivImageGallery_lblLoadingMessage');
			
			this.divImageList = document.getElementById ('esfdivImageGallery_divImageList');
			this.divHits = document.getElementById ('esfdivImageGallery_divHits');

			this.divImageContainer = document.getElementById ('esfdivImageGallery_divImageContainer');
			this.imgImage = document.getElementById ('esfdivImageGallery_imgImage');
			this.divPager = document.getElementById ('esfdivImageGallery_divPager');
		
			this.divImageContainer.style.height = this.divImageList.style.height = (heightGen - GetElementSize (this.divPager).Height - 20) + 'px';
			
			this.Reset ();
		},

		ShowNext : function ()
		{
			if (this.PageIndex < this.PageCount - 1)
			{
				this.PageIndex ++;
			}

			this.ShowImage ();
		},

		ShowPrevious : function ()
		{
			if (this.PageIndex > 0)
			{
				this.PageIndex --;
			}

			this.ShowImage ();
		},

		OnImageLoad : function ()
		{
			Hide (this.lblLoadingMessage);
			
			ShowFullCoverWithOpacity ();
		},

		Reset : function ()
		{
			this.PageIndex = 0;
			this.PageCount = 0;
			this.ImageSizeFactor = 1;

			this.BaseURLFormat = "";
		
			this.ImageSize = { Width: 1000, Height: 1000 };
			this.TumbnailImageSize = { Width: 120, Height: 120 };

			this.URLMD5_pItemCount_OCRHits = null;

			this.imgImage.src = '';
			this.divImageList.innerHTML = '';

			this.Hide ();
		},

		Hide : function ()
		{
			Hide (this.divImageGallery);
			HideFullCoverWithOpacity ();
		},

		ShowImage : function ()
		{
			var esfdivImageGallery_divImageList_imgX;
			var applicableBaseURL;
			var applicablePadPageIndex = null;
			var applicablePageIndex = null;
			var isMainImageAssigned = false;
			var currentHit;
			var hasHit;
			
			var j = 0;
			

			this.imgImage.src = '';
			this.divHits.innerHTML = '';
			this.divImageList.innerHTML = '';
			
			this.PageCount = 0;

			Show (this.divImageGallery);
			Show (this.lblLoadingMessage);

			this.lblLoadingMessage.innerHTML = "Cargando la imagen de la página {0}...".format ([this.PageIndex + 1]);

			CenterWindow (this.divImageGallery);
			

			for (var i = 0; i < this.URLMD5_pItemCount_OCRHits.length; i++)
			{
				this.PageCount += this.URLMD5_pItemCount_OCRHits [i].ItemsCount;

				applicableBaseURL = this.URLMD5_pItemCount_OCRHits [i].URLMD5;

				if (!isMainImageAssigned && this.PageIndex < this.PageCount)
				{	
					applicablePageIndex = Math.abs ((this.PageCount - this.URLMD5_pItemCount_OCRHits [i].ItemsCount) - this.PageIndex);

					applicablePadPageIndex = Pad (applicablePageIndex, 
						this.URLMD5_pItemCount_OCRHits [i].ItemsCount.toString ().length, "0");

					this.imgImage.src = this.BaseURLFormat.format ([applicableBaseURL, applicablePadPageIndex, this.ImageSize.Width, this.ImageSize.Height]);

					if (!IsNull (this.URLMD5_pItemCount_OCRHits [i].Hits))
					{
						for (var h = 0; h < this.URLMD5_pItemCount_OCRHits [i].Hits.length; h++)
						{
							currentHit = this.URLMD5_pItemCount_OCRHits [i].Hits [h];

							if (currentHit.PageIndex - 1 == applicablePageIndex)
							{
								currentHit.X0 *= this.ImageSizeFactor;
								currentHit.Y0 *= this.ImageSizeFactor;
								currentHit.X1 *= this.ImageSizeFactor;
								currentHit.Y1 *= this.ImageSizeFactor;

								this.divHits.innerHTML += '<div class="hit" title="{0}" style="position:absolute; left: {1}px; top: {2}px; width: {3}px; height: {4}px;"></div>'.format (
									[currentHit.WordSearchName, currentHit.X0, currentHit.Y0, currentHit.X1 - currentHit.X0, currentHit.Y1 - currentHit.Y0]);
							}
						}
					}

					isMainImageAssigned = true;
				}

				for (var k = 0; j < this.PageCount; j++)
				{
					applicablePadPageIndex = Pad (k, this.URLMD5_pItemCount_OCRHits [i].ItemsCount.toString ().length, "0");

					hasHit = 0;

					if (!IsNull (this.URLMD5_pItemCount_OCRHits [i].Hits))
					{
						for (var h = 0; h < this.URLMD5_pItemCount_OCRHits [i].Hits.length; h++)
						{
							currentHit = this.URLMD5_pItemCount_OCRHits [i].Hits [h];

							if (currentHit.PageIndex - 1 == k)
							{
								hasHit ++;
							}
						}
					}
					

					this.divImageList.innerHTML += '<img id="esfdivImageGallery_divImageList_img' + j + '" title="Ver la página ' + (j + 1) + 
						(this.URLMD5_pItemCount_OCRHits.length > 0 ? ' / Sección ' + (i + 1) + ': ' + (k + 1) : '') +
						(hasHit == 0 ? '' : ' (' + hasHit + ' hallazgos)') +
						'" onclick="esfImageGallery.PageIndex = ' + j + '; esfImageGallery.ShowImage (); " src="' + 
						this.BaseURLFormat.format ([applicableBaseURL, applicablePadPageIndex, this.TumbnailImageSize.Width, this.TumbnailImageSize.Height]) + '"></img>' + 
						'<div class="pagTitle" id="esfdivImageGallery_divImageList_imgTitle' + j + '">Pág. ' + (j + 1) + (hasHit == 0 ? '' : ' (' + hasHit + ' *)') +'</div>';

					k++;
				}

				if (this.URLMD5_pItemCount_OCRHits.length > 1)
				{
					this.divImageList.innerHTML += '<div class="endPartMarker" title="' + this.URLMD5_pItemCount_OCRHits [i].OnlyName + '">Fin Sección ' + (i + 1) + '</div>';
				}
			}


			this.lblPageCount.innerHTML = this.PageCount;
			this.lblPageIndex.innerHTML = (this.PageIndex + 1);
			

			if (this.PageCount == 1)
			{
				Hide (this.lnkPrevious);
				Hide (this.lnkNext);
			}
			else
			{
				Show (this.lnkPrevious);
				Show (this.lnkNext);
			}


			if (this.PageIndex == this.PageCount - 1)
			{
				this.lnkNext.disabled = 'disabled';
			}
			else
			{
				this.lnkNext.disabled = '';
			}


			if (this.PageIndex == 0)
			{
				this.lnkPrevious.disabled = 'disabled';
			}
			else
			{
				this.lnkPrevious.disabled = '';
			}
			

			esfdivImageGallery_divImageList_imgX = document.getElementById ('esfdivImageGallery_divImageList_img' + this.PageIndex);
			esfdivImageGallery_divImageList_imgX.className = 'selected';

			esfdivImageGallery_divImageList_imgXTitle = document.getElementById ('esfdivImageGallery_divImageList_imgTitle' + this.PageIndex);
			
			this.divImageList.scrollTop = (esfdivImageGallery_divImageList_imgX.offsetTop - GetElementSize (this.divPager).Height - 4) - (GetElementSize (esfdivImageGallery_divImageList_imgX).Height + GetElementSize (esfdivImageGallery_divImageList_imgXTitle).Height);
			
			ShowFullCoverWithOpacity ();
		}
	};

	
	esfImageGallery.Init ();
	

	return esfdivImageGallery;
}


function ShowFullCoverWithOpacity ()
{
	esfdivFullCoverWithOpacity.style.height = GetDocumentSize ().Height + 'px';

	Show (esfdivFullCoverWithOpacity);
}


function HideFullCoverWithOpacity ()
{
	Hide (esfdivFullCoverWithOpacity);
}


function HideCovers ()
{
	Hide (esfdivFullCoverWithOpacity);
	Hide (esfdivFullCover);
}


function ClearList (pList, pText)
{
	pList.options.length = 0;
	pList.disabled = 'disabled';

	if (IsNull (pText))
	{
		pText = '- Sin opción -';
	}

	pList.options [pList.options.length] = new Option (pText, '');
}


function LoadListBasicReference (pList, pItemsBasRef, pValueFieldName)
{
	ClearList (pList);

	
	if (IsNull (pItemsBasRef) || pItemsBasRef.length == 0)
	{
		return false;
	}

	pList.disabled = '';

	pList.options [0] = new Option ('- Seleccione uno -', '');

	if (IsNull (pValueFieldName))
	{
		pValueFieldName = "ID";
	}

	if (IsNull (pItemsBasRef [0][pValueFieldName]))
	{
		pValueFieldName = "Name";
	}

	for (var i = 0; i < pItemsBasRef.length; i++)
	{
		pList.options [pList.options.length] = new Option (pItemsBasRef [i].Name, pItemsBasRef [i][pValueFieldName]);
	}

	return true;
}


OnGetListComplete = function (pResponse, pProcessingDurationms, pLocalParams)
{
	LoadListBasicReference (pLocalParams, eval (pResponse));
}


window.onerror = function (pErrorMsg, pURL, pLineNumber)
{
	alert ("Error: " + pErrorMsg);

	return true;
}



function AddFuncEvent(pElem, pEventBasicName, pFunc) {
	if (IsNull(pElem)) { return; }

	if (pElem.addEventListener) {
		pElem.addEventListener(pEventBasicName, pFunc, false);
	}
	else {
		pElem.attachEvent("on" + pEventBasicName, pFunc);
	}
}


function AddLoadEvent(pFunc) {
	AddLoadEventObject(window, pFunc);
}

function AddLoadEventObject(pObject, pFunc) {
	AddFuncEvent(pObject, "load", pFunc);
}


AddLoadEvent (
	function ()
	{
		CreateFullCoverWithOpacity ();
		CreateFullCover ();
		CreateImageGallery ();

		FixContentSizes ();	


		var ifrContents = document.getElementById ("ifrContents");
	
		if (!IsNull (ifrContents))
		{
			AddLoadEventObject (ifrContents, FixContentSizes);
		}
	}
);